<template>
	<view class="login-wrap u-p-l-70 u-p-r-70 u-p-t-70">
		<view class="login-head u-text-center">
			<image src="../../static/image/logo.svg" style="width: 136rpx; height: 136rpx;"></image>
			<view class="u-font-32 u-m-t-40" style="color: #333;">欢迎登录我爱我房 </view>
		</view>
		<!-- open-type='getUserInfo' @getuserinfo='getUserInfo' -->
		<button @tap="login()" class="weixin-login u-m-b-50 u-felx u-text-center u-col-center u-font-32">
			微信授权
		</button>
		<view @click="goToDetail('/pages/phone/phone')" class="shouji u-felx u-text-center u-col-center u-font-32">
			手机登录
		</view>
		<u-divider>选择登陆方式</u-divider>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			// 获取头像昵称地址
			getUserInfo(e) {
				let _this = this;
				console.log(e);
				if (e.detail.rawData) {
					let rawData = JSON.parse(e.detail.rawData);
					uni.setStorageSync('rawData', e.detail.rawData);
					_this.$Router.push({
						path: '/pages/phone/phone'
					})
				}

			},
			login() {
				console.log(1)
				// uni.setStorageSync('rawData', '阿三大苏打');
				// uni.setStorageSync('phone','15573369325')
				// uni.setStorageSync('hourseList','aksdjajsdijasd')
				uni.getProvider({
					service: 'oauth',
					success(res) {
						console.log(res)
						uni.login({
							provider: 'weixin',
							success: function(loginRes) {
								console.log(JSON.stringify(loginRes), '登录授权');
								uni.getUserInfo({
									provider: 'weixin',
									success: function(infoRes) {
										console.log(infoRes.userInfo, '获取信息');
										uni.setStorageSync('rawData', infoRes.userInfo);
									}
								});

							},
							fail: function(error) {
								console.log(error)
								console.log(res)
								uni.showToast({
									icon: 'none',
									title: '登陆失败,请确保已安装或已登录微信',
									//title: res.errMsg,
									duration: 2000
								});
							}
						});
					},
					fail() {

					}
				})

			},
			goToDetail(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss">
	.login-wrap {
		width: 100vw;
		height: 100vh;

		.login-head {
			height: 200rpx;
		}

		.weixin-login {
			width: 614rpx;
			height: 100rpx;
			border-radius: 50rpx;
			background: #F9A832;
			box-shadow: 0px 4px 10px 0px rgba(249, 168, 50, 0.3);
			margin-top: 120rpx;
			line-height: 100rpx;
			color: #fff;
		}

		.shouji {
			height: 100rpx;
			border-radius: 50rpx;
			border: 2rpx solid #F9A832;
			font-family: PingFang-SC-Medium, PingFang-SC;
			color: #F9A832;
			line-height: 100rpx;
			margin-bottom: 30rpx;
		}
	}
</style>
